<%-- 
    Document   : list_order
    Created on : Jan 21, 2013, 2:09:20 PM
    Author     : SONY
--%>

<%@page import="entity.Product"%>
<%@page import="entity.SaleOrderDetail"%>
<%@page import="service.SaleOrderDetailServiceLocal"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="entity.SaleOrder"%>
<%@page import="java.util.List"%>
<%@page import="service.SaleOrderServiceLocal"%>
<%@page import="entity.MemberCustomer"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<% 
    MemberCustomer member = (MemberCustomer) session.getAttribute("user_member");
    int MemberID = member.getMemberID();
    SaleOrderServiceLocal saleOrderServiceLocal = (SaleOrderServiceLocal) application.getAttribute("saleOrderServiceLocal");
    List<SaleOrder> lstSaleOrder = saleOrderServiceLocal.getAllSaleOrders_byMemberID(MemberID);
    if(lstSaleOrder.size() > 0) { %>
<table id="cart" border=1 cellspacing=0 cellpadding=4 bordercolor=lightgray width="100%">
    <tr bgcolor=Tan style="color: white;">
            <th>Mã Đơn Hàng</th>
            <th>Ngày Đặt Hàng</th>
            <th>Tổng Tiền (đ)</th>
            <th>Trạng Thái</th>
    </tr>    
<%    int j = 0;
    for(int i = 0; i < lstSaleOrder.size(); i++) {
        String color = ++j % 2 == 0 ? "LightGoldenrodYellow" : "PaleGoldenrod";
        int SaleOrderID = lstSaleOrder.get(i).getSaleOrderID();
        Date OrderDate = lstSaleOrder.get(i).getOrderDate();
        String date_str = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(OrderDate);
        BigDecimal TotalPrice = lstSaleOrder.get(i).getTotalPrice();
        String Status = lstSaleOrder.get(i).getStatus();
%>
    <tr bgcolor="<%=color%>">
        <td align=center><%=SaleOrderID%></td>
        <td align=center><%=date_str%></td>
        <td align=center><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=TotalPrice%>"/></td>
        <td align=center style="font-weight: bold;"><%=Status%></td>
    </tr>
    <tr bgcolor="Tan">
        <td colspan="4">
            <table id="cart" border=1 cellspacing=0 cellpadding=4 bordercolor=lightgray width="560px" style="margin-left: 15px; margin-bottom: 15px;">
                <tr bgcolor=#383838 style="color: white;">
                    <th>#</th>
                    <th>Mã SP</th>
                    <th>Tên SP</th>
                    <th>Đơn Giá (đ)</th>
                    <th>Số Lượng</th>
                    <th>Thành Tiền (đ)</th>
                </tr>
<% 
    SaleOrderDetailServiceLocal saleOrderDetailServiceLocal = (SaleOrderDetailServiceLocal) application.getAttribute("saleOrderDetailServiceLocal");
    List<SaleOrderDetail> lstSaleOrderDetails = saleOrderDetailServiceLocal.getAllSaleOrderDetails_bySaleOrderID(SaleOrderID);
    int k = 0;
    for(int m = 0; m < lstSaleOrderDetails.size(); m++) {
        String color_table2 = ++k % 2 == 0 ? "White" : "#CCCCCC";  
        Product product = lstSaleOrderDetails.get(m).getProductID();
        String pid = product.getProductID();
        int qty = lstSaleOrderDetails.get(m).getOrderQty();
        BigDecimal totallinefmt = lstSaleOrderDetails.get(m).getLineTotal();
        String pname = product.getProductName();
        BigDecimal unitpricefmt = product.getUnitPrice();       
%>
                <tr bgcolor="<%=color_table2%>">
                        <td align=center><%=k%></td>
                        <td align=center><a href="../nonmember/product_details.jsp?<%=pid%>"><%=pid%></a></td>		
                        <td align=center><%=pname%></td>
                        <td align=center><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=unitpricefmt%>"/></td>
                        <td align=center><%=qty%></td>
                        <td align=center><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=totallinefmt%>"/></td>
                </tr>

<% } %>
            </table>
        </td>
    </tr>  
<% } %>
</table>  
<% } else { %>
<p style="font-weight:bold;">Không có bất kỳ đơn hàng nào trong thông tin đơn hàng.</p>
<% } %>
